#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Project: spd-sxmcc
"""
@author: lyndon
@time Created on 2018/9/14 10:11
@desc
"""
import json

import requests
from wxpy import Bot, embed

bot = Bot(cache_path="D:\iProject\myPython\com\\teradata\wechat\wxpy\wxpy.pkl")


def auto_ai(text):
    url = "http://www.tuling123.com/openapi/api"
    api_key = "你的图灵接口api"
    payload = {
        "key": api_key,
        "info": text,
        "userid": "老表"
    }
    r = requests.post(url, data=json.dumps(payload))
    result = json.loads(r.content)
    return "[极简机器人]  " + result["text"]

bot = Bot(cache_path="H:\PyCoding\Wxpy_test\wxpy.pkl")
print('极简机器人已经启动')
# 我的小号，测试需谨慎
my_friednd = bot.friends().search('极简XksA')[0]
# 如果想对所有好友实现机器人回复把参数my_friend改成chats = [Friend]
@bot.register(my_friednd)
def my_friednd_message(msg):
    print('[接收]' + str(msg))
    if msg.type != 'Text':
        ret = '你给我看了什么！[拜托]'
    else:
        ret = auto_ai(msg.text)
    print('[发送]' + str(ret))
    return ret
# 进入交互式的 Python 命令行界面，并堵塞当前线程
embed()